package com.gxa.jjty.core.config;

import com.gxa.jjty.core.interceptor.PermissionInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * springboot使用的拦截器的配置,
 * 通过实现WebMvcConfigurer接口
 * @author bill
 * @date 2021/11/11 10:40
 */

@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

    /**
     * 利用WebMvcConfigurer提供的拦截器注册方法,
     * 将自定义的PermissionInterceptor注册到spring的拦截器体系
     * @param registry
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(createPermissionInterceptor())
                //  要拦截的目标url
                .addPathPatterns("/**")
                // 要放行的目标
                .excludePathPatterns("/user/login");
    }

    @Bean
    public PermissionInterceptor createPermissionInterceptor(){
        return new PermissionInterceptor();
    }
}
